﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using GameStudio.IDE.Common.Events;
//using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.ServiceLocation;
using Utils.EventAggregator;

namespace GameStudio.IDE.Controls
{
    public class OpenItemControl:Control
    {
        public OpenItemControl()
        {
            // Configure open file dialog box
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".cs"; // Default file extension
            dlg.Filter = "Class (.cs)|*.cs"; // Filter files by extension

            // Show open file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                dlg.OpenFile();
                var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
                eventAggregator.GetEvent<OpenItemEvent>().Publish(filename);
            }         
        }
        
    }
}
